//################################################################################################################################//
//##                                                                                                                            ##//
//## This page is designed and developed to implement Make an Appointment  to the Dentist.                                                                     ##//
//##                                                                                                                            ##//
//## Author   : Akash Saxena                                                                                                          ##//
//## Dated    : 16 Sep '07                                                                                                   ##//
//##                                                                                                                            ##//
//################################################################################################################################//
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SiteManager;
using System.Data.SqlClient;

public partial class Dentist_MakeAppointment : System.Web.UI.Page
{
    int iUserId = 0;
    int iDentistid = 0;
    string sUserEmail = "";
    //Create object of Dentist and Manager Class
    clsDentist obDentist = new clsDentist();
    Manager objManager = new Manager(true,"ConnectionString");
    protected void Page_Load(object sender, EventArgs e)
    {
        localFunction lfunction = new localFunction();
        lfunction.checkPatientLogin(true);

       if(!Page.IsPostBack)
        {
                lblOutput.Text = "";
            
            if (Session["userID"] != null && Session["userID"].ToString().Trim() != "")
            {

                iUserId = Convert.ToInt32(Session["userID"]);
            }
            else
            {
                iUserId = 0;
            }
        
        }

            if (Session["useremail"] != null && Session["useremail"].ToString().Trim() != "")
            {
                sUserEmail = Session["useremail"].ToString();
            }
            if (!Equals(Request.QueryString["Id"], null))
            {
                if (Manager.IsNumeric(Request.QueryString["Id"].ToString()))
                {
                    iDentistid = Convert.ToInt32(Request.QueryString["Id"]);
                }
            }
        
    }
    protected void btnMakeAppointment_Click(object sender, EventArgs e)
    {

        string ToEmail = "";
        string MessageBody = string.Empty;

        SqlDataReader objDataReader = null;


        //add validations for querystring
        objDataReader = objManager.ExecuteQuery("select Email from tbl_dentists where id=" + iDentistid);

        if (objDataReader.HasRows)
        {
            objDataReader.Read();
            ToEmail = objDataReader["Email"].ToString();
            if (ToEmail.Length==0)
            {
                lblMsg.Text = " Message can not send. ";
                return;
            }
        }


        if (Session["LoginName"] != null && Session["LoginName"].ToString().Trim() != "")
        {
            MessageBody = Session["LoginName"].ToString() + " " + " is requesting for an appointment. <br>";
        }

        MessageBody += "Comments: <br>" + txtComments.Text;
        Response.Write("Hi");
        Response.End();

        if (objManager.sendMail(MessageBody, ToEmail, Session["LoginName"].ToString(), "Appointment Request", sUserEmail, ""))
        {
            lblOutput.Text = "Appointment Request has been sent successfuly";

            txtComments.Text = "";
        }
        else
        {
            lblOutput.Text = "Appointment Request sent failure! Please try again later.";
            //txtComments.Text = "";
        }
        objDataReader.Close();
        objDataReader.Dispose();

    }
}
